The present invention relates to a microcomputer having a built-in erasable nonvolatile memory, such as EEPROMs, flash memories, and FeRAMs.
As an example of a microcomputer having a built-in nonvolatile memory, a 1-chip microcomputer having a built-in EEPROM has been known, and this type of microcomputer has been used extensively as IC cards. FIG. 16 shows an example memory map of the 1-chip microcomputer used as the IC card.
In this memory map, addresses 0000H-7FFFH are allocated to a 32-kbyte ROM (Read Only Memory) area; addresses 8000H-9FFFH to an 8-kbyte EEPROM area; and addresses FF00H-FFFFH to a 256-byte RAM area.
To address 0000H is a start address, and the addresses 0000H-000FH are allocated to an interrupt vector. The 1-chip microcomputer is arranged in such a manner that a program branches to a ROM""s head address whenever the 1-chip microcomputer completes a reset action, and to a ROM""s interrupt routine area whenever an interrupt occurs. In other words, the 1-chip microcomputer reads out a program from the ROM""s head address at start-up. Interrupt routines are frequently carried out while a program is run, and the program has to return to the ROM""s interrupt routine area for each interrupt routine. Thus, in this 1-chip microcomputer, the program should be on the ROM area before it is run. Here, the EEPROM area is used either as a data area or a program area.
On the other hand, 1-chip microcomputers having nonvolatile memories other than EEPROM""s, that is, those having built-in flash memories have also been on the market. FIG. 17 shows an example memory map of the 1-chip microcomputer having a built-in flash memory.
In this memory map, addresses 0000H-7FFFH are allocated to a 32-kbyte flash memory area, and addresses FF00H-FFFFH to a 256-byte RAM (Random Access Memory) area.
Like the 1-chip microcomputer of FIG. 16 having a built-in EEPROM and used as the IC card, the address 0000H is a start address, and the addresses 0000H-000FH are allocated to an interrupt vector. The flash memory is divided into eight (8) blocks (BLOCKs 0-7) for every 4 kbytes, and data can be erased collectively per block. With this 1-chip microcomputer, the flash memory serving as a nonvolatile memory is provided on the assumption that the entire area is used as a program area. In other words, the flash memory is provided on the precondition that, while the program stored in the flash memory is run, neither can data be written into nor erased from the flash memory.
In order to write a program into the flash memory of the 1-chip microcomputer, the following methods can be adopted.
A first method uses a general PROM writer. In this method, generally, a device equipped with the 1-chip microcomputer is inserted into a socket of the PROM writer through a socket adapter, and data is written directly into the flash memory through an external terminal of the 1-chip microcomputer.
A second method is a popular method, by which data is written into the flash memory by means of a serial communication interface (hereinafter, referred to as SCI) furnished in the 1-chip microcomputer.
FIG. 18 shows an arrangement to carry out the second method. In the drawing, the 1-chip microcomputer 101 is connected to a personal computer 103 through a converting board 102. A writing program code stored in the personal computer 103 is transferred to the converting board 102 via a data line 104, and taken into an SCI 106 in the 1-chip microcomputer 101 from the converting board 102 via a serial data line 105. The program code is sent to a flash memory 108 from the SCI 106 via an internal bus 107 and written therein. A CPU 109 controls the flash memory 108, and the control program is stored in either a ROM 110 or a RAM 111.
In case of the 1-chip microcomputer of FIG. 16 used as the IC card, however, the EEPROM is mainly used for data storage. Thus, most of the program is stored in the non-erasable ROM and only a part thereof is stored in the EEPROM. Because the program stored in the ROM can not be overwritten, it can not be modified significantly. In particular, if the OS or the like of the IC card is stored in the ROM, upgrading the OS or the like is almost impossible.
Multi-application IC cards have been proposed recently, but if they contain the above-arranged 1-chip microcomputers, it is also impossible to additionally write other application programs once the IC card is issued.
Further, when a program different from the one stored in the ROM is additionally stored in the EEPROM so as to use this EEPROM as a data area in accordance with the additionally stored program, the program has to branch to the ROM before the job is started as previously mentioned. This is because, if the memory device (EEPROM) is seen from the CPU end, the same hardware address is assigned to the memory device for execution of both data read-out and data writing actions, but data read-out and data writing actions can not be executed simultaneously at the same address. Also, because the access program stored in the EEPROM as the additional program can not be transferred to the ROM to be stored therein, the access program already stored in the ROM can not be modified as desired. Thus, the program already stored in the ROM, namely a writing/erasing routine, is also used in this case, and therefore, data can not be written into or erased from the EEPROM in accordance with the additional program stored therein.
On the other hand, in case of the 1-chip microcomputer having a built-in flash memory, the flash memory is provided on the provision that it is replaced with a program ROM. Therefore, it is quite difficult to use the same flash memory as the program area and also as the data area simultaneously.
In case that the flash memory is used instead of the ROM, that is, the ROM is omitted, if a program is transferred to the RAM and stored therein, data can be written into/erased from the flash memory. However, if the program is merely transferred to the RAM as described above to use a part of the flash memory as a data area, the following problem occurs.
That is, if an interrupt request signal is generated from another block (for example, if an interrupt request signal 112 is generated from the SCI 106 in FIG. 18) when a program is transferred to the RAM from the flash memory and data is written into/erased from the data area in the flash memory in accordance with the program on the RAM, the program branches to the interrupt vector on the flash memory. However, because the data is being written into/erased from the flash memory, the interrupt vector can not be read out, and the system runs away out of control. In particular, this problem becomes apparent when nonvolatile memories including flash memories, etc. are used, because the nonvolatile memories require writing time and erasing time far longer than the CPU""s writing and read-out cycle. This problem invariably occurs with any kind of nonvolatile memories (including FeRAM) unless the writing and erasing cycle is matched with the CPU""s cycle. Thus, with the conventional 1-chip microcomputer having a built-in flash memory, it is quite difficult to use the same flash memory as the program area and also as the data area simultaneously.
Japanese Laid-open Patent Application No. 278895/1996 (Japanese Official Gazette, Tokukaihei No. 8-278895, publishing date: Oct. 22, 1996) discloses a 1-chip microcomputer having a built-in nonvolatile memory, which is arranged in such a manner so as to avoid the run away of the system when an interrupt occurs while data is being written into/erased from the flash memory by automatically making the interrupt vector jump to the RAM or any other memory.
However, this invention is directed to a technique to stabilize the system when external data is written into the general microcomputer having a built-in flash memory. In other words, this invention is silent about an arrangement to effect the data writing/erasing action with respect to the data area in the flash memory in accordance with the program stored in the same flash memory.
Also, in order to activate the function furnished with the arrangement of the above invention, the microcomputer has to be set to a mode different from a normal user mode. This is not preferable as an arrangement to solve the above problem.
Japanese Laid-open Patent Application No. 342374/1993 (Japanese Official Gazette, Tokukaihei No. 5-342374, publishing date: Dec. 24, 1993) discloses a technique to download a program in the initial stage. This invention relates to a technique to download program data into the microcomputer having a built-in flash memory, and like the foregoing prior art invention, the microcomputer has to be set to a mode different from a normal user mode. In other words, if this function is used in the normal mode, an interrupt routine can not be modified as desired in the user program (a program added arbitrarily by the user) because the interrupt vector is in a boot ROM.
The present invention is devised to solve the above problems, and therefore, has an object to provide a microcomputer having a built-in nonvolatile memory which can carry out a program additionally stored in the nonvolatile memory.
The present invention has another object to provide a microcomputer having a built-in nonvolatile memory, in which a nonvolatile memory can be also used as a data area in accordance with a program additionally stored in the same nonvolatile memory, in other words, the nonvolatile memory can be used as a program area and also as a data area simultaneously.
In order to fulfill the above and other objects, a microcomputer having a built-in nonvolatile memory of the present invention is characterized by being furnished with:
at least one erasable nonvolatile memory provided in a memory space of the microcomputer;
a boot ROM for storing an initial program to start up the microcomputer and a transfer program to transfer the initial program to the non-volatile memory; and
a control section for, when the nonvolatile memory stores no program, transferring the initial program to the nonvolatile memory in accordance with the transfer program, and subsequently removing the boot ROM from the memory space of the microcomputer.
According to the above arrangement, when the nonvolatile memory stores no program, the control section transfers the initial program stored in the boot ROM to the nonvolatile memory in accordance with the transfer program stored in the boot ROM, and stores the transferred program in the nonvolatile memory. Then, the control section removes the boot ROM from the memory space of the microcomputer.
Consequently, the initial program can be readily transferred to and then stored in the nonvolatile memory in the state same as immediately after the manufacturing and thus having stored no data.
Also, in case that a new program is additionally stored in the nonvolatile memory, the control section can carry out the additional program without concerning the boot ROM.
Further, the starting address of the interrupt routine can be positioned on the nonvolatile memory. Thus, even if programs including the OS, etc. are written over or new programs are added frequently on the nonvolatile memory, the interrupt routine can be carried out while the new program is run. Hence, the program can be modified more flexibly.
The microcomputer having a built-in nonvolatile memory may be arranged in such a manner that the microcomputer is further furnished with a RAM, and that:
the initial program includes a starting address of an interrupt routine;
the nonvolatile memory stores a transfer program to transfer a program stored in the nonvolatile memory to the RAM; and
the control section carries out a program stored in the RAM, transfers the program stored in the nonvolatile memory to the RAM in accordance with the transfer program, and when carrying out the program stored in the RAM, moves the head address of the interrupt routine included in the initial program from the nonvolatile memory to the RAM.
According to the above arrangement, when the program transferred to and stored in the nonvolatile memory in accordance with the transfer program, for example, a program for writing/erasing action with respect to the nonvolatile memory which is downloaded on the nonvolatile memory from an external device, is transferred to the RAM and run, the starting address of the interrupt routine is moved from the nonvolatile memory to the RAM.
Consequently, an action with respect to the nonvolatile memory used as the data area such as writing and erasing actions, can be executed in accordance with the program transferred from the nonvolatile memory to the RAM.
Even when an interrupt occurs while the program transferred from the nonvolatile memory is run from the RAM, the program does not run away out of control and the interrupt routine can be carried out in an adequate manner.
Another microcomputer having a built-in nonvolatile memory of the present invention is characterized by being furnished with:
a RAM;
at least one erasable nonvolatile memory for, provided in a memory space of the microcomputer, storing a head address of an interrupt routine, and a transfer program for transferring a first program having been stored therein to the RAM; and
a control section for carrying out a program stored in the RAM, and transfers the first program from the nonvolatile memory to the RAM in accordance with the transfer program, and when the first program stored in the RAM is run, moves a starting address of the interrupt routine onto the RAM from the nonvolatile memory.
According to the above arrangement, the first program stored in the nonvolatile memory, for example, a user program to carry out the writing and erasing with respect to the nonvolatile memory which has been downloaded on the nonvolatile memory from an external device, is transferred to the RAM in accordance with the transfer program, and when the first program is run on the RAM, the starting address of the interrupt routine is moved from the nonvolatile memory onto the RAM.
Consequently, an action with respect to the nonvolatile memory when it is used as the data area, for example, writing and erasing actions can be executed in accordance with the first program transferred from the nonvolatile memory to the RAM.
In addition, even when an interrupt occurs while the first program is run on the RAM, the program does not run away out of control, and the interrupt routine can be carried out in an adequate manner.
The microcomputer having a built-in nonvolatile memory may be arranged in such a manner that:
a program area and a data area are set on a same nonvolatile memory;
a second program to issue a command to use the data area on the same nonvolatile memory is stored in the program area; and
the control section uses the data area for data storage in accordance with the second program.
According to the above arrangement, the same nonvolatile memory can be readily used as the program area and also as the data area in accordance with the second program.
More specifically, for example, data of the specified number (of pieces) is successively read out from the specified address in the nonvolatile memory stored in the RAM in accordance with information related to the specified address and specified number of data in the non-volatile memory and the specified address in the RAM. Then, the data is successively read out from the RAM and written into the data area in the nonvolatile memory at the specified address.
For a fuller understanding of the nature and advantages of the invention, reference should be made to the ensuing detailed description taken in conjunction with the accompanying drawings.